package encrypt

import (
	"crypto"
	"fmt"
	"testing"
)

func TestRSAEncrypt(t *testing.T) {
	privateKeyStr := `-----BEGIN RSA PRIVATE KEY-----MIICXQIBAAKBgQDeXCKJ6kc+N/OCuogvj6tRXxKGOkRK7xPsfZcFJLdJowLLQm+sUw+45vNTUFg2H1enf5FGxcazc8/D+frQq8IDhJRMxerfA+hgeHlBL9P+uB1jh6qmvUVFN50ajLdxJPREGwDJcrcwgkzsa+DfarfLwTLCfisubPb1SVRt0ppedwIDAQABAoGBAJgRwr03L8npUewRzZlZU/yuXGjX6GSm5KVTrrihx4fgp8SChwT/OT1nFPnhdLJu9O9kWuJf1+haR7jreRDEpkWjJQu5lmVwdd8NTkuDHkyL8ipUOHclp+9zJKznqShk8JD2HAuqPiA5ezZCprPjXhBwjl6ZUltOMnNiH326v4BhAkEA537IfFaUYoz4SZ4Ygmbhhf1BkLIdS4TK/NaWhyF762u0/sc8iDzmsrnyCW9AR0bw8Kj52997TtjMhOnvE+hY4wJBAPXly8KtxXwe165J5LMgq4rTIB+Tpf2r+jkyw6YNCS5VO+LrPmxxl6cR2T7vJq1ytNnSJRMQEMl1uPlQJ0Yl3F0CQEq6nrWkrVny7+Oz6W2PEJZUXun61YIfZ/eevhD5OiuRJWhpoJzKLB7d78gj5bgcqoLFyYK07fVR/xOZANiIVMkCQG4twgf//s3nr/JrL6tHhzWT9f/QE38/cMXyRhIAI038aPH7QCQtHauBZts5IxZyoDA9ZdlNyIfMVM55KK/YxQ0CQQDdlCMYvAY6jrwWBYjOxBambK5/oJxSRpG/OmMfb6zqCmbA7BLpbnNTHTcHYMLqM9iShqw8+KOXfjenBdC+IS0X-----END RSA PRIVATE KEY-----`

	publicKeyStr := `-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDeXCKJ6kc+N/OCuogvj6tRXxKGOkRK7xPsfZcFJLdJowLLQm+sUw+45vNTUFg2H1enf5FGxcazc8/D+frQq8IDhJRMxerfA+hgeHlBL9P+uB1jh6qmvUVFN50ajLdxJPREGwDJcrcwgkzsa+DfarfLwTLCfisubPb1SVRt0ppedwIDAQAB-----END PUBLIC KEY-----`

	// 加密示例
	plaintext := "Hello, World!"
	ciphertext, err := RSAEncrypt(publicKeyStr, plaintext)
	if err != nil {
		fmt.Println("加密失败:", err)
		return
	}
	fmt.Println("加密后的密文:", ciphertext)

	// 解密示例
	decryptedText, err := RSADecrypt(privateKeyStr, ciphertext)
	if err != nil {
		fmt.Println("解密失败:", err)
		return
	}
	fmt.Println("解密后的明文:", decryptedText)

	// 签名示例
	signature, err := RSASign(privateKeyStr, ciphertext, crypto.SHA256)
	if err != nil {
		fmt.Println("签名失败:", err)
		return
	}
	fmt.Println("签名结果:", signature)

	// 验签示例
	verified := RSASignVerify(publicKeyStr, ciphertext, signature, crypto.SHA256)
	fmt.Println("验签结果:", verified)
}
